package com.cfh.web;



public class PageBean implements pageSuport {
	//public static final int DEFAULT_PAGERECORDERS = 3; //默认每页记录为10条
	private int currentPage = 1;//当前页:Action控制
	private int totalPages = 1;//总页数 :自己运算
	private int pageRecorders = 3; //每页记录数可以在初始化的时候修改//总数据数
	private boolean hasNextPage = false; //是否有下一页:自己运算
	private boolean hasPreviousPage = false; //是否有前一页 :自己运算
	private int totalRows = 0;//总记录数,由底层service提供，默认为0

	public PageBean() {

	}
	
	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		if(currentPage > getTotalPages())
			this.currentPage = getTotalPages();
		else if(currentPage <= 0)
			this.currentPage = 1;
		else
			this.currentPage = currentPage;
	}

	public int getTotalPages() {
		if (pageRecorders > 0)
			return (totalRows % pageRecorders == 0 ? totalRows / pageRecorders
					: totalRows / pageRecorders + 1);
		else
			return 1;
	}

	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}

	public int getPageRecorders() {
		return pageRecorders;
	}

	public void setPageRecorders(int pageRecorders) {
		this.pageRecorders = pageRecorders;
	}

	public boolean isHasNextPage() {
		return (currentPage < this.getTotalPages());
	}

	public void setHasNextPage(boolean hasNextPage) {
		this.hasNextPage = hasNextPage;
	}
	
	public boolean isHasPreviousPage() {
		return (getCurrentPage() > 1);
	}

	public void setHasPreviousPage(boolean hasPreviousPage) {
		this.hasPreviousPage = hasPreviousPage;
	}

	public int getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}

	public void description() {
		String description = "共有数据数:" + this.getTotalRows() + "共有页数: "
				+ this.getTotalPages() + "当前页数为:" + this.getCurrentPage()
				+ " 是否有前一页: " + this.isHasPreviousPage() + " 是否有下一页:"
				+ this.isHasNextPage();
		System.out.println(description);
	}
	
	public void reset(){
		currentPage = 1;
		pageRecorders = 3;
	}

	public int getLimit() {
		
		return pageRecorders ;
	}

	public int getStart() {
		
		return (currentPage-1) * pageRecorders ;
	}
}
